<!--
 * @Descripttion: 使用正则的方式-正则方法介绍
 * @Author: YuZhenJing
 * @Date: 2020-07-01 19:30:03
 * @LastEditors: YuZhenJing
 * @LastEditTime: 2020-07-01 19:53:18
-->
<!DOCTYPE html>
<html lang="zh_CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>正则方法介绍</title>
  </head>
  <body>
    <script>
      let title_style = "font-weight: bold;color:red;";
      let test_style = "padding-left:20px;color:yellow;";
      let text = "anyun666";
      console.log("%c正则相关方法：", title_style);
      console.log("%ctest:", test_style, /\d+/.test(text));
      let reg = /[a-z]/g;
      console.log("%cexec:", test_style, reg.exec(text)[0], reg.lastIndex);
      console.log("%cexec:", test_style, reg.exec(text)[0], reg.lastIndex);
      console.log(
        "%c在字符串中全局搜索 'man'，并用 'person' 替换。然后通过 compile() 方法，改变正则表达式，用 'person' 替换 'man' 或 'woman'，：",
        title_style
      );
      var str = "Every man in the world! Every woman on earth!";

      let patt = /man/g;
      str2 = str.replace(patt, "person");
      console.log("%ccompile:", test_style, str2);
      patt = /(wo)?man/g;
      patt.compile(patt);
      str2 = str.replace(patt, "person");
      console.log("%ccompile:", test_style, str2);
    </script>
  </body>
</html>
